package com.ymttest.database.sqlwapper;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.ymt.core.tool.Logger;
import com.ymt.database.SqlManager;
import com.ymttest.database.model.AdvanceOrder;
import com.ymttest.database.model.AdvanceApplyBill;
import com.ymttest.database.model.YmtAccountEntry;
import com.ymttest.utils.EnvSetup;

/************************************************************************************
 * @File name 
 * @Author : 
 * @Date : 
 * @Copyright : 洋码头
 ************************************************************************************/
public class AdvanceOrderDefaultWapper {
    static SqlManager manage;
    
    public AdvanceOrderDefaultWapper() {
		//manage = new SqlManager("mysql213");
		
    }

    /**
     * 使用 billId 查询凭证数据
     * 
     * @param billId
     * @return 
     * @throws InterruptedException
     */
    public List<AdvanceOrder> selectAdvanceOrder(Map map) throws InterruptedException {
    	//解决 查询缓存问题每次创建一个新的session 连接，用完之后，关闭
    	manage = new SqlManager("mysql213_"+EnvSetup.getEnv());
        List<AdvanceOrder> pia = manage.getSelectResults("com.ymttest.database.mapping.AdvanceOrderMapper.selectAdvanceOrder",
        		map);
        //manager2.getSession().clearCache();
        manage.close();
        return pia;
    }

    /**
     * 使用 billId 查询提前放款凭证
     * 
     * @param billId
     * @return 
     * @throws InterruptedException
     */
    public List<AdvanceApplyBill> selectAdvanceApplyBil(String billId) throws InterruptedException {
    	manage = new SqlManager("mysql213_"+EnvSetup.getEnv());
        Map map=new HashMap();
        map.put("bill_id", billId);      
        List<AdvanceApplyBill> pia = manage.getSelectResults("com.ymttest.database.mapping.AdvanceOrderMapper.selectAdvanceApplyBil",
        		map);
        manage.close();
        return pia;
    }

    /**
     * 关闭数据库连接
     */
    public void close() {
        manage.close();
    }

    @Override
    protected void finalize() throws Throwable {
        this.close();
        manage = null;
        super.finalize();
    }

    public static void main(String args[]) throws InterruptedException {

		Map map = new HashMap();
		//m.put("bill_id", "FZZ2016101300001");
		map.put("advance_status", 2);

		Logger.debug("rm:"+new AdvanceOrderDefaultWapper().selectAdvanceOrder(map));
		
		List<AdvanceApplyBill> rm=new AdvanceOrderDefaultWapper().selectAdvanceApplyBil("FZZ2016101300003");
		 
		
		Logger.debug("rm:"+rm);
    }
}
